package com.niit.hadoop.maxandmin;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

// 1. 实现Writable接口
public class MaxAndMinBean implements WritableComparable<MaxAndMinBean> {
    private long min;
    private long max;
    private int total;

    // 2. 创建空参构造
    public MaxAndMinBean() {
    }

    // 3. 序列化方法
    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeLong(min);
        dataOutput.writeLong(max);
        dataOutput.writeInt(total);
    }

    // 4. 反序列化方法
    @Override
    public void readFields(DataInput dataInput) throws IOException {
        // 5. 反序列化的顺序和序列化顺序一致
        min = dataInput.readLong();
        max = dataInput.readLong();
        total = dataInput.readInt();
    }

    // 6. 重写toString方法
    @Override
    public String toString() {
        return min + "\t" + max + "\t" + total;
    }

    public MaxAndMinBean(long min, long max, int total) {
        this.min = min;
        this.max = max;
        this.total = total;
    }

    public long getMin() {
        return min;
    }

    public void setMin(long min) {
        this.min = min;
    }

    public long getMax() {
        return max;
    }

    public void setMax(long max) {
        this.max = max;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    @Override
    public int compareTo(MaxAndMinBean o) {
        return 1;
    }
}
